//
//  RootViewController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/7/25.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()<UINavigationBarDelegate,UIGestureRecognizerDelegate>

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.interactivePopGestureRecognizer.delegate = self;
    if (@available(iOS 11.0, *)) {

    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
     [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName : [UIFont systemFontOfSize:17]}];
      [self.navigationBar setBackgroundImage:[UIColor imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
     [self.navigationBar setShadowImage:[[UIImage alloc] init]];
     [self setupLeftBarButton];
  
}

#pragma mark - 自定义返回按钮
- (void)setupLeftBarButton {
    
    
    NSArray *arrViewControllers = self.navigationController.viewControllers;
    
    if ([arrViewControllers indexOfObject:self] > 0)
        
    {
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
                                             initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                             style:UIBarButtonItemStyleDone
                                             target:self
                                             action:@selector(leftBarButtonClick)];
        
    }
    // 防止返回手势失效
    self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
}

#pragma mark - 返回按钮的点击事件
- (void)leftBarButtonClick {
    [self.navigationController popViewControllerAnimated:YES];
}



//+ (void)initialize{
//
//    UINavigationBar *navBar = [UINavigationBar appearance];
//
//    [navBar setBackgroundImage:[UIColor imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
//    //    [navBar setShadowImage:[UIImage imageWithColor:[UIColor clearColor]]];
//    NSMutableDictionary * titleAtt = [NSMutableDictionary dictionaryWithObjectsAndKeys:[UIColor  whiteColor],NSForegroundColorAttributeName, nil];
//    titleAtt[NSFontAttributeName] = [UIFont boldSystemFontOfSize:16];
//    [navBar setTitleTextAttributes:titleAtt];
//    UIBarButtonItem *barItem =  [UIBarButtonItem appearance];
//    NSMutableDictionary *textDict = [NSMutableDictionary dictionary];
//    textDict[NSForegroundColorAttributeName] = [UIColor whiteColor];
//    textDict[NSFontAttributeName] = [UIFont systemFontOfSize:14];
//    [barItem setTitleTextAttributes:textDict forState:UIControlStateNormal];
//    [[UISearchBar appearance] setSearchFieldBackgroundImage:[self __searchFieldBackgroundImage] forState:UIControlStateNormal];
//    if (@available(iOS 9.0, *)) {
//        UITextField*textField = [UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class],[UINavigationBar class]]];
//        [textField setDefaultTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}];
//    } else {
//    }
//}
//
//- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
//
//    if (self.childViewControllers.count > 0) {
//        viewController.view.backgroundColor =[UIColor whiteColor];// [UIColor colorWithHexString:@"F2F3F4"];
//        // 设置返回按钮
//        viewController.navigationItem.leftBarButtonItem =
//        [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(goBack)];
//        // 隐藏底部的 TabBar
//        viewController.hidesBottomBarWhenPushed = YES;
//    }
//
//    [super pushViewController:viewController animated:animated];
//}
//
//
//#pragma mark - UIGestureRecognizerDelegate
///// 手势识别将要开始
/////
///// @param gestureRecognizer 手势识别
/////
///// @return 返回 NO，放弃当前识别到的手势
//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
//    // 如果是根视图控制器，则不支持手势返回
//    return self.childViewControllers.count > 1;
//}
//- (void)goBack {
//    [self popViewControllerAnimated:YES];
//}
//
//+ (UIImage*)__searchFieldBackgroundImage {
//    UIColor*color = [UIColor whiteColor];
//    CGFloat cornerRadius = 3;
//    CGRect rect =CGRectMake(0,0,28,28);
//    UIBezierPath*roundedRect = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius];
//    roundedRect.lineWidth=0;
//    UIGraphicsBeginImageContextWithOptions(rect.size,NO,0.0f);
//    [color setFill];
//    [roundedRect fill];
//    [roundedRect stroke];
//    [roundedRect addClip];
//    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    return image;
//}
//
//-(id)naviPresentedViewController {
//    return self;
//}

@end
